/*
 * Copyright (c) 2010. raoqn
 */

package com.yfeng.goodjuhome.service.impl;

import com.yfeng.common.dao.IDao;
import com.yfeng.common.dao.Param;
import com.yfeng.exception.ServiceException;
import com.yfeng.goodjuhome.model.News;
import com.yfeng.goodjuhome.service.INewsService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * www.goodjuhome.com
 * Created by IntelliJ IDEA.
 * User: rqn
 * Date: 2010-8-14
 * Time: 14:18:09
 */
@Service("newsService")
public class NewsServiceImpl implements INewsService {

    private final static Log log = LogFactory.getLog(NewsServiceImpl.class);
	@Autowired
	public IDao baseDao;


    public int addNews(News news) throws ServiceException {
        return 0;
    }

    public int deleteNews(String[] id) throws ServiceException {
        return 0;
    }

    public int updateNews(News news) throws ServiceException {
        return 0;
    }

    public List queryNewsByUid(String uid) throws ServiceException {
        List result = null;
        try
        {
        result = baseDao.query("select t1.*,t3.name as typename from news t1,users t2,mb_news t3 where t1.uid=t2.id and t1.type=t3.id and t1.uid=:uid",new Param("uid", uid));
        return result;
        }
        catch(Exception e)
        {
            log.error(e.getMessage(),e);
            throw new ServiceException(e.getMessage(),e);
        }
        
    }

    public List queryNewsByUidAndType(String uid, String type) throws ServiceException {
        List result = null;
        try
        {
        result = baseDao.query("select t1.*,t3.name as typename from news t1,users t2,mb_news t3 where t1.uid=t2.id and t1.type=t3.id and t1.uid=:uid and t1.type='"+type+"'",new Param("uid", uid));
        return result;
        }
        catch(Exception e)
        {
            log.error(e.getMessage(),e);
            throw new ServiceException(e.getMessage(),e);
        }
    }

    public List queryNewsByUidAndType(String uid, String type,String limit) throws ServiceException {
        List result = null;
        try
        {
        result = baseDao.query("select t1.*,t3.name as typename from news t1,users t2,mb_news t3 where t1.uid=t2.id and t1.type=t3.id and t1.uid=:uid and t1.type='"+type+"' limit "+limit,new Param("uid", uid));
        return result;
        }
        catch(Exception e)
        {
            log.error(e.getMessage(),e);
            throw new ServiceException(e.getMessage(),e);
        }
    }
}
